<script>
function editMember(uuid){
	$('#add_member').modal();
	
	$.ajax({				
		type: "POST",
		async:false,
		url: "/admin/index.php?mod=member&act=ajax_info_member",			
		data: "uuid="+uuid,
		dataType: "json",									
		success: function (res) {
			$("#form-input-uuid").attr('value',res.uuid);
			$("#form-add-member-input-login").attr('value',res.login);
			$("#form-add-member-input-email").attr('value',res.email);
			$("#pass").attr('value',"<?=_cfg('input.hide.pass');?>");
			$("#form-add-member-input-cpass").attr('value',"<?=_cfg('input.hide.pass');?>");
		}
	});
	$('#myModalLabel').html('Edit member');
}
</script>
<div id="form-msg"></div>
<form action="javascript:add_admin()" id="add_member" method="post" class="modal hide form-horizontal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="hideModal('add_member');">×</button>
    <h4 id="myModalLabel">Add member</h4>
  </div>
  <div class="modal-body">
	<div id="form-error"></div>
	<div class="form-controls">
		<div class="control-group">
			<label class="control-label-left">Login</label>
			<div class="controls">
				<input type="text" id="form-add-member-input-login"  name="login">
				<input type="hidden" id="form-input-uuid"  name="uuid">
			</div>
		</div>
		<div class="control-group">
			<label class="control-label-left">Email</label>
			<div class="controls">
				<input type="text" id="form-add-member-input-email" name="email">
			</div>
		</div>
		<div class="control-group">
			<label class="control-label-left">Password</label>
			<div class="controls">
				<input type="password" id="pass" id="form-add-member-input-pass" name="pass">
			</div>
		</div>
		<div class="control-group">
			<label class="control-label-left">Confirm Password</label>
			<div class="controls">
				<input type="password" id="form-add-member-input-cpass" name="cpass">
			</div>
		</div>
	</div>
  </div>
  <div class="modal-footer">
	<input class="btn" type="reset" value="Close" data-dismiss="modal" aria-hidden="true" onclick="hideModal('add_member');">
	<input class="btn btn-primary" type="submit" value="Save">
  </div>
</form>
<div class="row">
	<div class="span12">
		<div class="bookmark-title">
			<h4>Admins</h4>
			<hr>
		</div>
	</div>
	<form action="<?=$currentUrl;?>" method="POST" name="member_list">
	<input type="hidden" name="filter_<?php echo $fltInfo['__name__']; ?>" value="on"/>
		<div class="span5">
			<div class="btn-group">
				<label for="btn_block"   class="btn btn-small">Block</label>
				<label for="btn_unblock" class="btn btn-small">Unblock</label>	
				<label for="btn_delete"  class="btn btn-small">Delete</label>
			</div>
			<input id="btn_block"   class="hide" type="submit" name="act" value="Block"   onclick="return isCheck();">
			<input id="btn_unblock" class="hide" type="submit" name="act" value="Unblock" onclick="return isCheck();">
			<input id="btn_delete"  class="hide" type="submit" name="act" value="Delete"  onclick="return isCheck(1);">
			
			<div class="btn-group">
				<a id="btn_add_admin" href="javascript:void(0)" role="button" class="btn btn-small btn-primary" data-toggle="modal"><i class="icon-user icon-white"></i>&nbsp; Add admins</a>
			</div>
		</div>
		<div class="span4 pagination pagination-small">
			<?php include('tpl/bootstrap_pager.php')?>
		</div>
		<div class="span3 button-filter text-right">
			<label for="btn_reset_filter" class="btn btn-small">Reset Filter</label>
			<label for="btn_filter" class="btn btn-small">Filter</label>
			<input id="btn_reset_filter" class="hide" type="submit" name="filter_reset" value="Reset Filter">
			<input id="btn_filter" class="hide" type="submit" name="filter_set"   value="Filter">
		</div>
		<div class="span12">
			<table class="table table-bordered table-condensed table-hover">
				<col style="width:25px;">
				<col style="width:155px;">
				<col>
				<col style="width:190px;">
				<col style="width:135px;">
				<col style="width:100px;">
				<col style="width:95px;">
				<thead>
					<tr class="tr-sorter">
						<th>&nbsp;</th>
						<?php Sorter::show($srtInfo['login_key'],'Login')?>
						<?php Sorter::show($srtInfo['email'],'Email')?>
						<?php Sorter::show($srtInfo['last_visit'],'Last visit')?>
						<?php Sorter::show($srtInfo['last_ip'],'Last IP')?>
						<?php Sorter::show($srtInfo['blocked'],'Status')?>
						<th class="text-center">Action</th>
					</tr>
				</thead>
				<tr class="info table-filter-tr">
					<td><input name="all" type="checkbox" onclick="selectAll('uuid[]', this.checked,'member_list')"></td>
					<td><input  class="span2" type="text" name="flt_login_key" value="<?=$fltInfo['login_key'];?>"></td>
					<td><input  class="span2" type="text" name="flt_email" value="<?=$fltInfo['email'];?>"></td>
					<td>
						<div class="pull-left">
							<input placeholder="From" id="date_from" name="flt_last_visit_from" class="input-xl datepicker" type="text" value="<?=strtotime($fltInfo['last_visit_from']) > 0 ? _dformat($fltInfo['last_visit_from']) : ''?>"><label for="date_from" class="icon-calendar"></label>
							<span class="help-inline"></span>
						</div>
						<div class="pull-left">
							<input placeholder="to" id="date_to" name="flt_last_visit_to" class="input-xl datepicker" type="text" value="<?=strtotime($fltInfo['last_visit_to']) > 0 ? _dformat($fltInfo['last_visit_to']) : ''?>"><label for="date_to" class="icon-calendar"></label>
						</div>
					</td>
					<td><input  class="input-xxl" type="text" name="flt_ip" value="<?=$fltInfo['ip'];?>"></td>
					<td>
						<select class="input-small" name="flt_blocked">
							<?=Html_Form::makeOptions(_cfg('member.status'),$fltInfo['blocked'],' '); ?>
						</select>
					</td>
					<td>&nbsp;</td>
				</tr>
				<?php foreach($rows as $r):?>
				<tr id="<?=$r['uuid'];?>" class="<?=($r['blocked'])?'':'error';?> <?=$r['class']?>">
					<td><input name="uuid[]" value="<?=$r['uuid'];?>" type="checkbox" ></td>
					<td class="login"><?=$r['login_key'];?></td>
					<td class="email"><?=$r['email'];?></td>
					<td><?=(!_dformat($r['last_visit'],_cfg("format.datetime")))?"no visit":_dformat($r['last_visit'],_cfg("format.datetime"))?></td>
					<td><?=($r['ip'])?:'no visit';?></td>
					<td class="id-status" id="status-<?=$r['uuid'];?>"><?=($r['blocked'])?"active":"blocked";?></td>
					<td class="ico-td">
						<div class="btn-group">
						  <button type="button" onclick="editMember('<?=$r['uuid'];?>')" class="btn btn-mini"><i class="icon-pencil"></i></button>
						  <button id="block-<?=$r['uuid'];?>" onclick="memberBlock('<?=$r['uuid'];?>');" type="button" class="id-block btn btn-mini <?=($r['blocked'])?:"btn-warning";?>"><i class="icon-lock <?=($r['blocked'])?:"icon-white";?>"></i></button>
						  <button type="button" class="id-delete btn btn-mini" onclick="deleteMember('<?=$r['uuid'];?>');"><i class="icon-trash"></i></button>
						</div>
					</td>
				</tr>
				<?php endforeach;?>
				<?php if(count($rows)==1):?>
				<tr>
					<td colspan="8">
						<?='No results match your search...';?>
					</td>
				</tr>
				<?php endif; ?>
			</table>
		</div>
	</form>
</div>